//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(){
	
	var obj={"text":'新建受让交易',"url":contextRootPath+'/creditDealController/prepareExecute/toAdd'};
	parent.showObj(obj);
}

//修改 事件
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	
	//如果没有选中 数据则
	if(v_ids == ""){
		//alert("请选择待修改的数据！");
		art.dialog({title: '提示', content: '请选择待修改的数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		//alert("请选择一条数据！");
		art.dialog({title: '提示', content: '请选择一条数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
	var cooperorgCode = iframe.iframeObj["table"].getSelectedObjs("cooperorgCode");
	var contractCode = iframe.iframeObj["table"].getSelectedObjs("contractCode");
	var dealCode = iframe.iframeObj["table"].getSelectedObjs("dealCode");
	var cooperativeAgencyDealStatus = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus");
	var obj={"text":'修改受让交易',"url":contextRootPath+'/creditDealController/prepareExecute/toBackTransfereeDealUpdate?contractCode=' + contractCode + "&dealCode=" + dealCode + "&cooperativeAgencyDealStatus=" + cooperativeAgencyDealStatus + "&cooperorgCode=" + cooperorgCode + "&idDeal=" + v_ids};
	parent.showObj(obj);
}


//删除 事件
function deleteData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	var dealType = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus").join(",");
	var dealCodes = iframe.iframeObj["table"].getSelectedObjs("dealCode").join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		//alert("请选择待删除的数据！");
		art.dialog({title: '提示', content: '请选择待删除的数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
	var passage = dealType.indexOf('01');
	var complete = dealType.indexOf('02');
	
	if(!(complete>-1||passage>-1)){
		//alert("只有新建或者在途才能删除！");
		art.dialog({title: '提示', content: '只有“交易状态”为“新建”或者“在途”才能删除！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
//	if(confirm("您确认要删除选择的数据吗？")){
//        $.ajax({
//            type:"POST",
//            dataType : "json",
//            url:contextRootPath+"/creditDealController/deleteDeal?dealCodes="+dealCodes,
//            success:function(msg){
//            	alert(msg.msg);
//            	var v_status = msg.status;
//            	//删除成功后
//            	if(v_status.indexOf('ok') >-1){
//            		iframe.iframeObj["table"].removeSelectedRow();
//            	}
//            }
//        });
//    }
	
	art.dialog({title: '询问', content: '您确认要删除选择的数据吗？', ok: function () {
		  $.ajax({
				url: contextRootPath+"/creditDealController/deleteDeal?dealCodes="+dealCodes,
				type: 'post',
				dataType: 'json',
				success: function(msg) {
					if(msg.status=="ok"){
						art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
						var winObj = parent.tabs.getTabWinByTitle("受让交易");
						if(winObj)
							winObj.location.reload();
						//parent.tabs.close();
					}else{
						art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
					}
					
					
				}
			});
	  }, cancel: true, icon: 'question', lock:true, background:'#600', opacity: 0.10});
	
}
/**
 * 查看受让交易信息
 * @param vId
 */
function viewData(vId){
	var dealCode = iframe.iframeObj["table"].dataMap[vId].dealCode;
	var cooperorgCode =iframe.iframeObj["table"].dataMap[vId].cooperorgCode;
	var contractCode = iframe.iframeObj["table"].dataMap[vId].contractCode;
	var obj = {
		"text" : '查看受让交易信息',
		"url" : contextRootPath + '/creditDealController/prepareExecute/toView?dealCode=' + dealCode +"&cooperorgCode="+cooperorgCode+"&contractCode="+contractCode
	};
	parent.showObj(obj);
	
}

function updateSettle(){
	$.ajax({
		url: contextRootPath+"/creditDealController/realTimeUpdateSettleResult",
		type: 'post',
		dataType: 'json',
		success: function(msg) {
				art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
		}
	});
}
